@@ -1,4 +1,7 @@ |
||
1 | 1 |
class BlogPostsController < ApplicationController |
2 |
+ |
|
3 |
+ before_filter :authenticate_user, only: [:edit, :update, :destroy, :list] |
|
4 |
+ |
|
2 | 5 |
before_action :set_blog_post, only: [:show, :edit, :update, :destroy] |
3 | 6 |
|
4 | 7 |
# GET /blog_posts |
@@ -75,4 +78,8 @@ class BlogPostsController < ApplicationController |
||
75 | 78 |
def blog_post_params |
76 | 79 |
params.require(:blog_post).permit(:title, :slug, :content, :published, :description, :author_id) |
77 | 80 |
end |
81 |
+ |
|
82 |
+ def authenticate_user |
|
83 |
+ redirect_to new_user_session_path, alert: 'You dont have permission to access that page!' unless current_user && current_user.is_admin? |
|
84 |
+ end |
|
78 | 85 |
end |
@@ -13,4 +13,10 @@ class User < ActiveRecord::Base |
||
13 | 13 |
name = self.first_name.to_s + ' ' + self.last_name.to_s |
14 | 14 |
return name |
15 | 15 |
end |
16 |
+ |
|
17 |
+ def is_admin? |
|
18 |
+ #self.admin == true |
|
19 |
+ true |
|
20 |
+ end |
|
21 |
+ |
|
16 | 22 |
end |
@@ -5,7 +5,7 @@ |
||
5 | 5 |
<ul class="thumbnails"> |
6 | 6 |
<% @blog_posts.each do |post| %> |
7 | 7 |
<li class="span3"> |
8 |
- <div class="thumbnail"> |
|
8 |
+ <div class="thumbnail" style="height: 300px;"> |
|
9 | 9 |
<img src="http://placehold.it/300x200" alt=""> |
10 | 10 |
<h3><%= link_to post.title, post_path(post) %></h3> |
11 | 11 |
<p><%= post.description %></p> |
@@ -5,11 +5,8 @@ |
||
5 | 5 |
|
6 | 6 |
<%= @blog_post.content.html_safe %> |
7 | 7 |
|
8 |
-<hr> |
|
9 | 8 |
|
10 |
-<% if user_signed_in? %> |
|
11 |
- <%= link_to 'Edit', edit_blog_post_path(@blog_post) %> | |
|
12 |
- <%= link_to 'Back', blog_path %> |
|
13 |
-<% else %> |
|
14 |
- <%= link_to 'Back', blog_path %> |
|
15 |
-<% end %> |
|
9 |
+<div style="margin-top: 40px; text-align: center;"> |
|
10 |
+<%= link_to 'Edit', edit_blog_post_path(@blog_post), :class => 'btn btn-small' if user_signed_in? %> |
|
11 |
+<%= link_to 'Back', blog_path, :class => 'btn btn-small' %> |
|
12 |
+</div> |
@@ -0,0 +1,4 @@ |
||
1 |
+<footer> |
|
2 |
+ <hr> |
|
3 |
+ <p style="text-align: center;">© Company 2014</p> |
|
4 |
+</footer> |
@@ -56,26 +56,14 @@ |
||
56 | 56 |
|
57 | 57 |
<div class="container top-container "> |
58 | 58 |
<div class="row"> |
59 |
- <div class="span9"> |
|
59 |
+ <div class="span12"> |
|
60 | 60 |
<%= bootstrap_flash %> |
61 | 61 |
<%= yield %> |
62 | 62 |
</div> |
63 |
- <div class="span3"> |
|
64 |
- <div class="well sidebar-nav"> |
|
65 |
- <h3>Sidebar</h3> |
|
66 |
- <ul class="nav nav-list"> |
|
67 |
- <li class="nav-header">Sidebar</li> |
|
68 |
- <li><%= link_to "Link1", "/path1" %></li> |
|
69 |
- <li><%= link_to "Link2", "/path2" %></li> |
|
70 |
- <li><%= link_to "Link3", "/path3" %></li> |
|
71 |
- </ul> |
|
72 |
- </div><!--/.well --> |
|
73 |
- </div><!--/span--> |
|
74 | 63 |
</div><!--/row--> |
75 | 64 |
|
76 |
- <footer> |
|
77 |
- <p>© Company 2014</p> |
|
78 |
- </footer> |
|
65 |
+ <%= render 'layouts/footer' %> |
|
66 |
+ |
|
79 | 67 |
|
80 | 68 |
</div> <!-- /container --> |
81 | 69 |
|